package chai.ningning.creation;

public class ThreadTest4 {

    public static void main(String[] args) {

        System.out.println(Thread.currentThread());

        // 从 Java 8 开始，匿名类内部访问外部的局部变量时，可以不用final修饰
        final int bound = 100 ; // Java 8 开始这里的 final 修饰符可以省略

        //创建Runnable实例
        Runnable runnable = new Runnable() {
            private boolean isPrime(int n){
                for (int i = 2; i < n; i++) {
                    if (n % i == 0){
                        return false;
                    }
                }
                return true;
            }

            @Override
            public void run() {
                for (int i = 2; i < bound; i++) {
                    if (isPrime(i)){
                        System.out.print(i+" ");
                    }
                }
                System.out.println();
            }
        };

        Thread thread = new Thread(runnable);
        thread.start();
        System.out.println(thread);
    }
}
